package com.graduation.rescuematerial.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.graduation.rescuematerial.mapper.CatalogMapper;
import com.graduation.rescuematerial.pojo.Catalog;
import com.graduation.rescuematerial.service.ICatalogService;
import com.graduation.rescuematerial.vo.CatalogVo;
import com.graduation.rescuematerial.vo.RespBean;
import com.graduation.rescuematerial.vo.RespBeanEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CaiShuangLian
 * @since 2022-04-24
 */
@Service
public class CatalogServiceImpl extends ServiceImpl<CatalogMapper, Catalog> implements ICatalogService {

    @Autowired
    private CatalogMapper catalogMapper;
    @Override
    public RespBean getCatalogByCompanyName(String companyName) {
        return RespBean.success(catalogMapper.getCatalogByCompanyName(companyName));
    }

    @Override
    public RespBean getAllCatalog() {
        return RespBean.success(catalogMapper.getAllCatalog());
    }

    @Override
    public RespBean addOne(CatalogVo addCatalogVo) {
        if(catalogMapper.addOne(addCatalogVo.getBaseCatalog())<1){
            return RespBean.error(RespBeanEnum.INSERT_ERROR,"添加失败");
        }
        return RespBean.success();
    }

    @Override
    public RespBean updateInfo(CatalogVo addCatalogVo) {
        if(catalogMapper.updateInfo(addCatalogVo.getBaseCatalog())<1){
            return RespBean.error(RespBeanEnum.UPDATE_ERROR,"更新失败");
        }
        return RespBean.success();
    }

    @Override
    public RespBean fuzzyQuery(String key) {
        return RespBean.success(catalogMapper.fuzzyQuery(key));
    }

    @Override
    public RespBean catalogDropDownBox() {
        return RespBean.success(catalogMapper.catalogDropDownBox());
    }


}
